package view;

import model.OnScreen;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Toast;

import com.vandorenmes.argusv4.R;

/**
 * A splash screen to initiate the application
 * <p>Retreives all available snippets from the server</p> 
 */
public class Splash extends Activity 
{
	private Handler _toastHandler;
	private Toast _toastje;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_splash);
		
		this._toastHandler = new Handler();
		_toastje = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);
		
//		new ServiceConnection(this).execute();
		OnScreen.getInstance().getWebServiceConnector().connectToServer(this);
	}
	
	public synchronized void makeToast(final String msg)
	{
		_toastHandler.post(new Runnable() {
			@Override
			public void run() {	
				_toastje.cancel();	// cancel previous toast			
				
				_toastje = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT);
				_toastje.show();
			}
		});
		
	}
}
